#include <iostream>

class Car       //被装饰的抽象类
{
public:
    virtual void show() = 0;
protected:
    std::string name;
};

class BMW : public Car
{
public:
    BMW()
    {
        this->name = " 宝马 ";
    }
    void show()
    {
        std::cout<<name<<std::endl;
    }

};

class Decorate : public Car     //继承被装饰类的对象
{
public:
    void decorate(Car * c)
    {
        this->c = c;
    }
protected:
    Car * c;
};

class Navigator : public Decorate
{
public:
    void show()
    {
        std::cout<<"导航";
        c->show();
    }
};

class SelfDrive : public Decorate
{
public:
    void show()
    {
        std::cout<<"自动驾驶";
        c->show();
    }
};

class VoiceControl : public Decorate
{
public:
    void show()
    {
        std::cout<<"语音控制";
        c->show();
    }
};

int main()
{
    Car * c = new BMW;

    Decorate *n = new Navigator;
    n->decorate(c);
    n->show();          //输出导航 宝马
/* 使用继承可以重叠加功能 */
    Decorate *s = new SelfDrive;
    s->decorate(n);
    s->show();          //输出自动驾驶导航 宝马 

    Decorate *v = new VoiceControl;
    v->decorate(s);
    v->show();          //输出语音控制自动驾驶导航 宝马 
/* 也可以卸下功能 */
    c->show();          //输出宝马

    return 0; 
}